package org.jeecg.modules.client;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class ChannelManager {
    public static final AttributeKey<String> SCID = AttributeKey.valueOf("SCID");
    public static final AttributeKey<String> loginAuth = AttributeKey.valueOf("loginAuth");
    private  static  final ConcurrentHashMap<String, Channel> channels = new ConcurrentHashMap<>();

    public static void  registerChannel(String channelKey, Channel channel) {
        channels.put(channelKey, channel);
        System.out.println("Channel registered: " + channelKey);
    }

    public Channel getChannel(String channelId) {
        return channels.get(channelId);
    }

    public void removeChannel(Channel channel) {
        channels.remove(channel.id().asShortText());
        System.out.println("Channel removed: " + channel.id().asShortText());
    }
}